# -*- coding: utf-8 -*-
# create JSON-RPC client

import utils.jsonrpc as jsonrpc #@UnresolvedImport
from os import path

ROOT_DIR = path.dirname(__file__)
UNIXSOCKET = path.join(ROOT_DIR,"socketipc")

#server = jsonrpc.ServerProxy(jsonrpc.JsonRpc20(), jsonrpc.TransportTcpIp(addr=("127.0.0.1", 31415)))
#server = jsonrpc.ServerProxy(jsonrpc.JsonRpc20(), jsonrpc.TransportTcpIp(addr=("127.0.0.1", 8086)))

server = jsonrpc.ServerProxy(jsonrpc.JsonRpc20(), jsonrpc.TransportUnixSocket(addr=UNIXSOCKET))

# call a remote-procedure (with positional parameters)

while True:
    var = raw_input("Enter something: ")
    if "quit" in var:
        break
    else:
        if "add1" in var:
            #var2 = raw_input("IP to add: ")
            var3 = raw_input("Port to add: ")
            try:
                server.addwatcher1("127.0.0.1", int(var3))
            except jsonrpc.RPCTransportError, e:
                print "No connection : %s" % e
        if "remove1" in var:
            #var2 = raw_input("IP to add: ")
            var3 = raw_input("Port to remove: ")
            try:
                server.removewatcher1("127.0.0.1", int(var3))
            except jsonrpc.RPCTransportError, e:
                print "No connection: %s" % e
        if "add2" in var:
            #var2 = raw_input("IP to add: ")
            var3 = raw_input("Port to add: ")
            try:
                server.addwatcher2("127.0.0.1", int(var3))
            except jsonrpc.RPCTransportError, e:
                print "No connection : %s" % e
        if "remove2" in var:
            #var2 = raw_input("IP to add: ")
            var3 = raw_input("Port to remove: ")
            try:
                server.removewatcher2("127.0.0.1", int(var3))
            except jsonrpc.RPCTransportError, e:
                print "No connection: %s" % e
                
print "Quit"